const Hapi = require('hapi');
require('env2')('./.env')
const config = require('./config/config');
const routesHello = require('./routes/hello-hapi');
const routesShops = require('./routes/shops');
const routesOrders = require('./routes/orders');
// 引入自定义的 hapi-swagger 插件配置
const pluginHapiSwagger = require('./plugins/hapi-swagger');

const server = new Hapi.Server();

server.connection({
    host: config.host,
    port: config.port
});

const init = async() => {
    await server.register([
        // 为系统使用 hapi-swagger
        ...pluginHapiSwagger
    ]);
    server.route([
        // 配置一个简单的 hello hapi 接口
        ...routesHello,
        ...routesShops,
        ...routesOrders
    ])
    // 启动服务
    await server.start();
    console.log(`Server running at: ${server.info.uri}`);
}

init();